package com.main.by.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.main.by.dao.GeneralDao;
import com.main.by.dao.TaskDao;
import com.main.by.entity.vo.SubmitVO;
import com.main.by.entity.vo.TaskVO;

@Repository
public class TaskDaoImpl implements TaskDao{
	
	Logger logger = Logger.getLogger(this.getClass());
	
	@Autowired
	private GeneralDao generalDao;

	@Override
	public boolean insterTask(TaskVO taskInfo) throws Exception {
		boolean successful = generalDao.saveEntity("insert into renren_task(title,count,content,minPic,maxPic,flag,cateId,taskDate,taskDesc) values(?,?,?,?,?,?,?,?,?)", 
				new Object[]{taskInfo.getTitle(),taskInfo.getCount(),taskInfo.getContent(),taskInfo.getMinPic(),taskInfo.getMaxPic(),taskInfo.getFlag(),taskInfo.getCateId(),
				taskInfo.getTaskDate(),taskInfo.getTaskDesc()});
		return successful;
	}
	
	@Override
	public List<TaskVO> findAllTask() throws Exception {
		return (List<TaskVO>) generalDao.findAllEntity(TaskVO.class, "select * from renren_task");
	}

	@Override
	public TaskVO findTaskById(int taskId) throws Exception {
		return generalDao.getEntity(TaskVO.class,new Object[]{taskId});
	}

	@Override
	public boolean deleteTaskById(int taskId) throws Exception {
		return generalDao.updateEntity("delete from renren_task where taskId=? ",new Object[]{taskId});
	}

	@Override
	public boolean saveTaskInfo(TaskVO taskInfo) throws Exception {
		boolean successful = generalDao.updateEntity("update renren_task set title=?,count=?,content=?,minPic=?,maxPic=?,flag=?,cateId=?,taskDate=?,taskDesc=?  where taskId=?", 
				new Object[]{taskInfo.getTitle(),taskInfo.getCount(),taskInfo.getContent(),taskInfo.getMinPic(),taskInfo.getMaxPic(),taskInfo.getFlag(),taskInfo.getCateId(),
					taskInfo.getTaskDate(),taskInfo.getTaskDesc(),taskInfo.getTaskId()});
		return successful;
	}

	@Override
	public boolean insterSubmitTask(SubmitVO submitTaskInfo) throws Exception {
		boolean successful = generalDao.saveEntity("insert into renren_submit(taskId,userId,taskPic,telphone,aliplay,bankPay,userQQ,blog,info,flag,submitDate) values(?,?,?,?,?,?,?,?,?,?,?)",
				new Object[]{submitTaskInfo.getTaskId(),submitTaskInfo.getUserId(),submitTaskInfo.getTaskPic(),submitTaskInfo.getTelphone(),submitTaskInfo.getAliplay(),submitTaskInfo.getBankPay(),submitTaskInfo.getUserQQ(),
						submitTaskInfo.getBlog(),submitTaskInfo.getInfo(),submitTaskInfo.getFlag(),submitTaskInfo.getSubmitDate()});
		return successful;
	}
	
	@Override
	public List<TaskVO> selectTaskByCate(int taskId) throws Exception {
		return (List<TaskVO>) generalDao.getEntity(TaskVO.class, "select * from renren_task where taskId=?",new Object[taskId]);
	}
}
